import React from 'react';
import {
  Form,
  Input,
  Button,
  Table,
  Icon,
  Radio,
  InputNumber,
  Checkbox,
  Modal,
  message,
  notification,
  Affix,
  Upload
} from 'antd';

import InnerTable from 'components/DBTable/InnerTable.js';
import UploadAudio from './UploadAudio.js';
import ajax from '../../../utils/ajax';

const FormItem = Form.Item;
const ButtonGroup = Button.Group;

var _this;

/**
 * 内部表格组件
 */
class ExhibitInnerTable extends InnerTable {

  constructor(props) {
    super(props);
    this.state.moduleName = 'exhibit';
    this.state.modalUpAudioVisible = false;
    this.state.defaultFileList = [];
  }

  prepareToolBar = function () {
    let isButtondisabled=false;

    if(this.state.selectedRowKeys.length > 0){  // 是否选择
      isButtondisabled=true;
    }

   if(this.state.selectedRowKeys.length > 1){  // 是否选择了多项
      isButtondisabled=false;
    }

    var items = [];

    if (this.props.tableConfig.showUpload) {
      items.push(<Button key='audioUpBtn' type="primary" disabled={!isButtondisabled} onClick={this.onClickUpAudio}>
        <Icon type="edit"/>上传音频
      </Button>)
    }

    return items;
  }


  //上传音频
  onClickUpAudio =()=>{
      this.setState({ defaultfile:this.state.selectedRows[0].voice,modalUpAudioVisible: true,updateAudioId:this.state.selectedRowKeys[0]});
  }

  hideModalUpAudio=()=>{
     this.setState({ modalUpAudioVisible: false });
  }

  //更新音频
  handleModalUpAudioOk=()=>{
    if(this.state.voiceKey == null || this.state.voiceKey == ""){
      notification.error({
        message: "音频上传中",
        description: "请等待~~~"
      });
      return;
    }

    _this=this;
    ajax.post({
      url:"/exhibition/updateVoice",
      params:{exhibitionId:this.state.updateAudioId,voiceKey:this.state.voiceKey},
      success:function(res){
         _this.setState({ modalUpAudioVisible: false });  
         _this.props.refresh(); //刷新列表
         message.success('修改成功');     
      }
    })
  }

  getAudio=(data)=>{
    this.setState({voiceKey:data.key,defaultfile:data});
  }

  //新modal
  getUniqueModal=()=>{
      return (
      <div>
        <Modal title="展品音频" visible={this.state.modalUpAudioVisible} onOk={this.handleModalUpAudioOk}
            onCancel={this.hideModalUpAudio}>
             <UploadAudio uploadVideo={this.getAudio} defaultFileList={this.state.defaultfile} updateAudioId={this.state.updateAudioId}/>
          </Modal>
      </div>);
  }

} 

export default ExhibitInnerTable;
